package com.sun.personal.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

/**
 * @author syh
 * @date 2021/7/6 13:30
 */
public class TestFutureTask {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        FutureTask<Integer> futureTask = new FutureTask(()->{
            System.out.println(Thread.currentThread().getName()+ " come in callable");
                    TimeUnit.SECONDS.sleep(4);
            return 1024;
        });

        FutureTask<Integer> futureTask2 = new FutureTask(()->{
            System.out.println(Thread.currentThread().getName()+ " come in callable");
            TimeUnit.SECONDS.sleep(4);
            return 2048;
        });

        new Thread(futureTask,"aa").start();
        new Thread(futureTask2,"bb").start();

        while(!futureTask.isDone()){
            System.out.println("***wait");
        }
        System.out.println(futureTask.get());
        System.out.println(Thread.currentThread().getName()+" come over");
    }



    class MyThread implements Runnable {
        @Override
        public void run() {

        }
    }


    class MyThread2 implements Callable{
        @Override
        public Integer call() throws Exception {
            System.out.println(Thread.currentThread().getName() + "come in callable");
            return 200;
        }
    }
}

